1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.UnixSocketAddress; 26 27 private import gio.SocketAddress; 28 private import gio.c.functions; 29 public import gio.c.types; 30 private import glib.ConstructionException; 31 private import glib.Str; 32 private import glib.c.functions; 33 private import gobject.ObjectG; 34 35 36 /** 37 * Support for UNIX-domain (also known as local) sockets. 38 * 39 * UNIX domain sockets are generally visible in the filesystem. 40 * However, some systems support abstract socket names which are not 41 * visible in the filesystem and not affected by the filesystem 42 * permissions, visibility, etc. Currently this is only supported 43 * under Linux. If you attempt to use abstract sockets on other 44 * systems, function calls may return %G_IO_ERROR_NOT_SUPPORTED 45 * errors. You can use g_unix_socket_address_abstract_names_supported() 46 * to see if abstract names are supported. 47 * 48 * Since GLib 2.72, #GUnixSocketAddress is available on all platforms. It 49 * requires underlying system support (such as Windows 10 with `AF_UNIX`) at 50 * run time. 51 * 52 * Before GLib 2.72, `<gio/gunixsocketaddress.h>` belonged to the UNIX-specific 53 * GIO interfaces, thus you had to use the `gio-unix-2.0.pc` pkg-config file 54 * when using it. This is no longer necessary since GLib 2.72. 55 */ 56 public class UnixSocketAddress : SocketAddress 57 { 58 /** the main Gtk struct */ 59 protected GUnixSocketAddress* gUnixSocketAddress; 60 61 /** Get the main Gtk struct */ 62 public GUnixSocketAddress* getUnixSocketAddressStruct(bool transferOwnership = false) 63 { 64 if (transferOwnership) 65 ownedRef = false; 66 return gUnixSocketAddress; 67 } 68 69 /** the main Gtk struct as a void* */ 70 protected override void* getStruct() 71 { 72 return cast(void*)gUnixSocketAddress; 73 } 74 75 /** 76 * Sets our main struct and passes it to the parent class. 77 */ 78 public this (GUnixSocketAddress* gUnixSocketAddress, bool ownedRef = false) 79 { 80 this.gUnixSocketAddress = gUnixSocketAddress; 81 super(cast(GSocketAddress*)gUnixSocketAddress, ownedRef); 82 } 83 84 85 /** */ 86 public static GType getType() 87 { 88 return g_unix_socket_address_get_type(); 89 } 90 91 /** 92 * Creates a new #GUnixSocketAddress for @path. 93 * 94 * To create abstract socket addresses, on systems that support that, 95 * use g_unix_socket_address_new_abstract(). 96 * 97 * Params: 98 * path = the socket path 99 * 100 * Returns: a new #GUnixSocketAddress 101 * 102 * Since: 2.22 103 * 104 * Throws: ConstructionException GTK+ fails to create the object. 105 */ 106 public this(string path) 107 { 108 auto __p = g_unix_socket_address_new(Str.toStringz(path)); 109 110 if(__p is null) 111 { 112 throw new ConstructionException("null returned by new"); 113 } 114 115 this(cast(GUnixSocketAddress*) __p, true); 116 } 117 118 /** 119 * Creates a new #GUnixSocketAddress of type @type with name @path. 120 * 121 * If @type is %G_UNIX_SOCKET_ADDRESS_PATH, this is equivalent to 122 * calling g_unix_socket_address_new(). 123 * 124 * If @type is %G_UNIX_SOCKET_ADDRESS_ANONYMOUS, @path and @path_len will be 125 * ignored. 126 * 127 * If @path_type is %G_UNIX_SOCKET_ADDRESS_ABSTRACT, then @path_len 128 * bytes of @path will be copied to the socket's path, and only those 129 * bytes will be considered part of the name. (If @path_len is -1, 130 * then @path is assumed to be NUL-terminated.) For example, if @path 131 * was "test", then calling g_socket_address_get_native_size() on the 132 * returned socket would return 7 (2 bytes of overhead, 1 byte for the 133 * abstract-socket indicator byte, and 4 bytes for the name "test"). 134 * 135 * If @path_type is %G_UNIX_SOCKET_ADDRESS_ABSTRACT_PADDED, then 136 * @path_len bytes of @path will be copied to the socket's path, the 137 * rest of the path will be padded with 0 bytes, and the entire 138 * zero-padded buffer will be considered the name. (As above, if 139 * @path_len is -1, then @path is assumed to be NUL-terminated.) In 140 * this case, g_socket_address_get_native_size() will always return 141 * the full size of a `struct sockaddr_un`, although 142 * g_unix_socket_address_get_path_len() will still return just the 143 * length of @path. 144 * 145 * %G_UNIX_SOCKET_ADDRESS_ABSTRACT is preferred over 146 * %G_UNIX_SOCKET_ADDRESS_ABSTRACT_PADDED for new programs. Of course, 147 * when connecting to a server created by another process, you must 148 * use the appropriate type corresponding to how that process created 149 * its listening socket. 150 * 151 * Params: 152 * path = the name 153 * type = a #GUnixSocketAddressType 154 * 155 * Returns: a new #GUnixSocketAddress 156 * 157 * Since: 2.26 158 * 159 * Throws: ConstructionException GTK+ fails to create the object. 160 */ 161 public this(string path, GUnixSocketAddressType type) 162 { 163 auto __p = g_unix_socket_address_new_with_type(Str.toStringz(path), cast(int)path.length, type); 164 165 if(__p is null) 166 { 167 throw new ConstructionException("null returned by new_with_type"); 168 } 169 170 this(cast(GUnixSocketAddress*) __p, true); 171 } 172 173 /** 174 * Checks if abstract UNIX domain socket names are supported. 175 * 176 * Returns: %TRUE if supported, %FALSE otherwise 177 * 178 * Since: 2.22 179 */ 180 public static bool abstractNamesSupported() 181 { 182 return g_unix_socket_address_abstract_names_supported() != 0; 183 } 184 185 /** 186 * Gets @address's type. 187 * 188 * Returns: a #GUnixSocketAddressType 189 * 190 * Since: 2.26 191 */ 192 public GUnixSocketAddressType getAddressType() 193 { 194 return g_unix_socket_address_get_address_type(gUnixSocketAddress); 195 } 196 197 /** 198 * Tests if @address is abstract. 199 * 200 * Deprecated: Use g_unix_socket_address_get_address_type() 201 * 202 * Returns: %TRUE if the address is abstract, %FALSE otherwise 203 * 204 * Since: 2.22 205 */ 206 public bool getIsAbstract() 207 { 208 return g_unix_socket_address_get_is_abstract(gUnixSocketAddress) != 0; 209 } 210 211 /** 212 * Gets @address's path, or for abstract sockets the "name". 213 * 214 * Guaranteed to be zero-terminated, but an abstract socket 215 * may contain embedded zeros, and thus you should use 216 * g_unix_socket_address_get_path_len() to get the true length 217 * of this string. 218 * 219 * Returns: the path for @address 220 * 221 * Since: 2.22 222 */ 223 public string getPath() 224 { 225 return Str.toString(g_unix_socket_address_get_path(gUnixSocketAddress)); 226 } 227 228 /** 229 * Gets the length of @address's path. 230 * 231 * For details, see g_unix_socket_address_get_path(). 232 * 233 * Returns: the length of the path 234 * 235 * Since: 2.22 236 */ 237 public size_t getPathLen() 238 { 239 return g_unix_socket_address_get_path_len(gUnixSocketAddress); 240 } 241 }